package com.xinzhi.service.impl;

import com.xinzhi.mapper.TwogradeindexMapper;
import com.xinzhi.pojo.TwoGradeIndex;
import com.xinzhi.service.TwoGradeIndexService;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class TwoGradeIndexServiceImpl implements TwoGradeIndexService {
    @Autowired
    private TwogradeindexMapper twogradeindexMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
//    指标框架制定修改

    @Override
    public Result update(Integer two_indexid,String two_index) {

        if (two_index == null && two_indexid == null) {
            return Result.error("二级指标内容和id不能为空");
        }
        redisTemplate.delete("twogradeindex");
        int update = twogradeindexMapper.update(two_indexid,two_index);
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        redisTemplate.delete("twogradeindex");
        redisUtils.get("twogradeindex");
        return update > 0 ? Result.ok("修改成功") : Result.error("修改失败");
    }


    /**
     * 指标框架制定下发修改状态
     * @param two_index
     * @return
     */
    @Override
    public Result   updateState(String two_index) {
        if (two_index == null){
            return Result.error("参数不能为空");
        }
        int i = twogradeindexMapper.updateState(two_index);
        twogradeindexMapper.updatede(two_index);
        return i>0 ? Result.ok("下发成功") : Result.error("下发失败");
    }
}
